#ifndef PULSE_HPP
#define PULSE_HPP

#include "audio.hpp"

#include <pulse/simple.h> //PulseAudio 的简单 API
#include <pulse/error.h>
#include <thread>

class PulseReader : public AudioReader
{
    pa_simple *pa = nullptr;
    bool is_paused = false;  //暂停状态

    bool loop();
    std::thread read_thread; //用于异步执行 loop() 方法, 实现音频读取
    uint64_t monotonic_clock_start = 0;

    public:
    ~PulseReader();
    void cleanup();
    bool create_stream();

    bool init() override;
    void start() override; //启动音频读取线程
    void pause() override;
    void resume() override;
    uint64_t get_time_base() const override; //获取音频读取的起始时间
};

#endif /* end of include guard: PULSE_HPP */
